﻿using Client.Common.Extensions;
using Client.Todo.Common;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Client.Todo.Extendsions;
namespace Client.Todo.Views
{
    /// <summary>
    /// MainView.xaml 的交互逻辑
    /// </summary>
    public partial class MainView : Window
    {
        private readonly IEventAggregator eventAggregator;
        private readonly IDialogHostService dialogHostService;

        public MainView(IEventAggregator  eventAggregator,IDialogHostService dialogHostService)
        {
            InitializeComponent();

            //注册提示
            eventAggregator.RegisterMessage(arg =>
            {
                snackbar.MessageQueue.Enqueue(arg);
            });

            //注册等待消息窗口
            eventAggregator.Register(arg =>
            {
                dialogHost.IsOpen = arg.IsOpen;
                if (dialogHost.IsOpen)
                {
                    dialogHost.DialogContent = new ProgressView();
                }
            });

            this.eventAggregator = eventAggregator;
            this.dialogHostService = dialogHostService;
        }

        private void MenuToggleButton_OnClick(object sender, RoutedEventArgs e)
        {

        }

        private void btnWindowMin_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void btnWindowMax_Click(object sender, RoutedEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
            {
                this.WindowState = WindowState.Normal;
            }
            else
            {
                this.WindowState = WindowState.Maximized;
            }
        }

        private async void btnWindowClose_Click(object sender, RoutedEventArgs e)
        {
            var dialogRes = await dialogHostService.Question(content: "确定要退出吗?");
            if(dialogRes.Result == Prism.Services.Dialogs.ButtonResult.OK)
            {
                this.Close();
            }
        }

        private void navHeader_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }

        private void navHeader_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
            {
                this.WindowState = WindowState.Normal;
            }
            else
            {
                this.WindowState = WindowState.Maximized;
            }
        }

        private void navMenuBars_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            drawerHost.IsLeftDrawerOpen = false;
        }
    }
}
